home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <alloc.h>
- #include <string.h>
- #include "dtypes.h"
- #include <conio.h>
- #include <ctype.h>
- #include "nkeybd.h"
- #include <graphics.h>
- #include "ginput.h"
-
- static int x,y,l,maxlen;
- static char b[80];
-
- /*
- * Function : void _add_char(int ch)
- * Purpose : Append a character to buf
- * Date : 10/06/1988 22:40:56
- */
- void _add_char(int ch)
- {
- char bf[5];
-
- if (l<maxlen) {
- b[l++]=ch;
- b[l]=NULL;
- bf[1]=0;
- bf[0]=ch;
- moveto(x,y); outtext(bf);
-
- x+=textwidth("A");
-
- } else putchar(7);
-
- } /* void _add_char(int ch) */
-
- /*
- * Function : void _del_char(void)
- * Purpose : Deletes the last character in the buffer
- * Date : 10/06/1988 22:48:38
- */
- void _del_char(void)
- {
- char bf[5];
-
- if (l>0) {
-
- x-=textwidth("A");
-
- setcolor(CGA_WHITE);
- bf[0]=b[l-1];
- bf[1]=0;
- moveto(x,y); outtext(bf);
- setcolor(BLACK);
-
- b[--l]=NULL;
-
- } else putchar(7);
- } /* void _del_char(void) */
-
- /*
- * Function : char *ggetline(int len, char *s)
- * Purpose : Gets a LEN length string from keyboard and stores it in S.
- * Date : 10/06/1988 20:06:03
- */
- char *ggetline(int len, char *s)
- {
- int ox,oy,a;
- BOOL first;
- char ch;
-
- x=ox=getx(); y=oy=gety();
- l=0; maxlen=len;
- first=TRUE;
-
- setcolor(BLACK);
- moveto(x,y);
- if (*s) outtext(s);
- moveto(ox,oy);
-
- do {
- moveto(x,y+8);
- setcolor(BLACK);
- linerel(8,0);
- moveto(x,y);
-
- while (!kbhit())
- ;
- ch=getkey(); ch=toupper(ch);
-
- moveto(x,y+8);
- setcolor(CGA_WHITE);
- linerel(8,0);
- setcolor(BLACK);
- moveto(x,y);
-
- if (isalnum(ch)) {
-
- if (first) {
- moveto(ox,oy);
- setcolor(CGA_WHITE);
- outtext(s);
- setcolor(BLACK);
- moveto(ox,oy);
- first=FALSE;
- }
- _add_char(ch);
-
- } else {
- switch(ch) {
- case ESC: moveto(ox,oy); setcolor(CGA_WHITE);
- if (first)
- outtext(s);
- else outtext(b);
- strcpy(b," ");
- first=FALSE;
- ch=CR;
- /* No break statement here */
-
- case CR : if (first) {
- strcpy(b,s);
- x+=strlen(s);
- }
-
- moveto(ox,oy);
- b[len]=NULL;
- break;
-
- case BS : _del_char();
- if (l==0) {
- moveto(ox,oy);
- if (*s) outtext(s);
- moveto(ox,oy);
- first=TRUE;
- }
- break;
-
- default : putchar(7); break;
- }
- } /* if not printable character */
- } while (ch!=CR);
-
- strcpy(s,b);
-
- return(s);
- } /* char *ggetline(int len, char *s) */
-
-